package com.example.log;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-11-28
 * Time: 11:21
 */
public class FacadePartternDemo {
    //实现灯的门面
    class FacadeLight{
        private LivingRoomLight livingRoomLight = new LivingRoomLight();
        private HallLight hallLight = new HallLight();
        private DiningLight diningLight = new DiningLight();
        public void lightOn(){
            livingRoomLight.on();
            hallLight.on();
            diningLight.on();
        }
        public void lightOff(){
            livingRoomLight.off();
            hallLight.off();
            diningLight.off();
        }
    }
    //先定义一个灯的接口
    interface Light{
        void on();
        void off();
    }
    //三个不同的场景实现灯的接口
    class LivingRoomLight implements Light{
        @Override
        public void on(){
            System.out.println("打开客厅灯");
        }

        @Override
        public void off() {
            System.out.println("关闭客厅灯");
        }
    }
    class HallLight implements Light{

        @Override
        public void on() {
            System.out.println("打开走廊灯");
        }

        @Override
        public void off() {
            System.out.println("关闭走廊灯");
        }
    }
    class DiningLight implements Light{

        @Override
        public void on() {
            System.out.println("打开餐厅灯");
        }

        @Override
        public void off() {
            System.out.println("关闭餐厅灯");
        }
    }
}
